Documentation for class gadget

Inherits from 	graphic 

Properties declared in gadget 
	frame 

Class Methods declared in gadget 
	new 

Methods declared in gadget 
	any 
		composite_image(image, operation, x, y, source_area) 
		dissolve_image(image, delta, x, y, source_area) 
		draw_arc(x1, y1, radius, angle1, angle2) 
		draw_circle(x1, y1, radius) 
		draw_line(x1, y1, x2, y2) 
		draw_polygon(point_collection) 
		draw_polyline(point_collection) 
		draw_post_script(string) 
		draw_rectangle(x, y, width, height) 
		draw_string(string, x, y) 
		fill_circle(x1, y1, radius) 
		fill_polygon(point_collection) 
		fill_rectangle(x, y, width, height) 
		frame 
		height 
		paint_rectangle(x, y, width, height, type) 
		position 
		reset_draw_state 
		resize(width, height) 
		resize_by(dw, dh) 
		set_draw_color(color) 
		set_draw_dash(number_collection, offset) 
		set_draw_font(font) 
		set_draw_linewidth(width) 
		set_draw_rotation(angle) 
		set_draw_scaling(x, y) 
		set_draw_translation(dx, dy) 
		shape(x, y, width, height) 
		shape_by(dx, dy, dw, dh) 
		size 
		width 
		x 
		y 
	drawing 
		composite_image(image, operation, x, y, source_area) 
		dissolve_image(image, delta, x, y, source_area) 
		draw_arc(x1, y1, radius, angle1, angle2) 
		draw_circle(x1, y1, radius) 
		draw_line(x1, y1, x2, y2) 
		draw_polygon(point_collection) 
		draw_polyline(point_collection) 
		draw_post_script(string) 
		draw_rectangle(x, y, width, height) 
		draw_string(string, x, y) 
		fill_circle(x1, y1, radius) 
		fill_polygon(point_collection) 
		fill_rectangle(x, y, width, height) 
		paint_rectangle(x, y, width, height, type) 
		reset_draw_state 
		set_draw_color(color) 
		set_draw_dash(number_collection, offset) 
		set_draw_font(font) 
		set_draw_linewidth(width) 
		set_draw_rotation(angle) 
		set_draw_scaling(x, y) 
		set_draw_translation(dx, dy) 
	get 
		frame 
	size 
		frame 
		height 
		position 
		resize(width, height) 
		resize_by(dw, dh) 
		shape(x, y, width, height) 
		shape_by(dx, dy, dw, dh) 
		size 
		width 
		x 
		y 

Class 
#begin_class
gadget 
The class gadget is a subclass of the class graphic. 
Gadgets are graphical objects that you usually find in the CraftMan ToolBox. Examples of gadgets are button, movie, post_script, stretch_frame and slide_show.
The class gadget is a so-called abstract class. It implements the methods that is shared by all the different gadget classes. 
Note: You cannot create instances of an abstract class.

The Draw State
All the drawing messages (draw_line, draw_circle etc) uses a draw-state in the gadget that specifies the current drawing parameters. These are:
draw_color - default is black
draw_dash - default is none 
draw_font - default is helvetica_12 
draw_linewidth - default is 1.0
draw_rotation - default is 0.0 
draw_scaling - default is (1, 1) 
draw_translation - default is (0, 0) 
#end_class

Properties 

#begin_property
frame 
Stores the frame of the gadget in the coordinate system of the slide the gadget is located in.
#end_property

Methods 

#begin_method
composite_image(image, operation, x, y, source_area) 
Composites an image with an operation to a point (x, y) in the gadget. source_area is the area of the image that will be composited. If you want the whole image to be composited source_area should be nil.
Valid operations are:
#clear
#sover
#dover
#xor
#copy
#sin
#din
#plusd
#sout
#dout
#plusl
#satop
#datop
Returns self.
Ex:
Assume that {slide 6} is the base-slide of a window.
{slide 6}:composite_image({image next}, #copy, 10, 10, nil)
will draw {image next} at position (10, 10).
for i from 1 to 100 do
	x := the_program:random_number(0, 350)
	y := the_program:random_number(0, 350)
	{slide 6}:composite_image({image next}, #copy, x, y, nil)
end for
will draw {image next} 100 times at random positions.
Compositing is much faster than moving pictures around.
Note: This is a drawing operation that will temporarily change the appearance of the gadget. As soon as the gadget is redisplayed the result of this drawing operation will disappear.
#end_method

#begin_method
dissolve_image(image, delta, x, y, source_area) 
Composites an image with a transparency factor delta to a point (x, y) in the gadget. delta should be between 0.0 (totally transparent) and 1.0 (totally opaque). source_area is the area of the image that will be composited. If you want the whole image to be composited source_area should be nil.
Returns self.
Ex:
Assume that {slide 6} is the base-slide of a window.
{slide 6}:dissolve_image({image next}, 0.5, 10, 10, nil)
will draw {image next} at position (10, 10) partly transparent.
for i from 1 to 100 do
	x := the_program:random_number(0, 350)
	y := the_program:random_number(0, 350)
	d := the_program:random_percent
	{slide 6}:dissolve_image({image next}, d, x, y, nil)
end for
will draw {image next} 100 times at random positions and transparency.
Compositing is much faster than moving pictures around.
Note: This is a drawing operation that will temporarily change the appearance of the gadget. As soon as the gadget is redisplayed the result of this drawing operation will disappear.
#end_method

#begin_method
draw_arc(x1, y1, radius, angle1, angle2) 
Draws an arc with the center point in (x1, y1), with the radius radius and from angle angle1 and to angle angle2.
Returns self.
Ex:
Assume that {slide 6} is the base-slide of a window.
{slide 6}:draw_arc(100, 100, 50, 0, 90)
will draw a 90 degree arc.
for r from 0 to 50 by 5 do
	{slide 6}:draw_arc(100, 100, r, 0, 90)
end for
will draw a number of 90 degree arcs with different radius.
Note: This is a drawing operation that will temporarily change the appearance of the gadget. As soon as the gadget is redisplayed the result of this drawing operation will disappear.
#end_method

#begin_method
draw_circle(x1, y1, radius) 
Draws a circle with the center point in (x1, y1) and the radius radius.
Returns self.
Ex:
Assume that {slide 6} is the base-slide of a window.
{slide 6}:draw_circle(100, 100, 50)
will draw a circle.
for r from 0 to 50 by 5 do
	{slide 6}:draw_circle(100, 100, r)
end for
will draw a number of circles with different radius.
Note: This is a drawing operation that will temporarily change the appearance of the gadget. As soon as the gadget is redisplayed the result of this drawing operation will disappear.
#end_method

#begin_method
draw_line(x1, y1, x2, y2) 
Draws a line from the point (x1, y1) to the point (x2, y2).
Returns self.
Ex:
Assume that {slide 6} is the base-slide of a window.
{slide 6}:draw_line(0, 0, 100, 100)
will draw a line from (0, 0) to (100, 100).
for s from 0 to 200 by 5 do
	{slide 6}:draw_line(0, 0, s, 100)
end for
will draw a number of lines from origo.
Note: This is a drawing operation that will temporarily change the appearance of the gadget. As soon as the gadget is redisplayed the result of this drawing operation will disappear.
#end_method

#begin_method
draw_polygon(point_collection) 
Draws a polygon with the points in the point_collection.
Returns self.
Ex:
Assume that {slide 6} is the base-slide of a window.
{slide 6}:draw_polygon([{10 10} {90 20} {65 280} {25 230}])
will draw a polygon with four corners.
c := []
for i from 1 to 100 do
	x := the_program:random_number(0, 350)
	y := the_program:random_number(0, 350)
	p := {point}:new(x, y)
	c:add_last(p)
end for 
{slide 6}:draw_polygon(c)
will draw a polygon with 100 random corners.
Note: This is a drawing operation that will temporarily change the appearance of the gadget. As soon as the gadget is redisplayed the result of this drawing operation will disappear.
#end_method

#begin_method
draw_polyline(point_collection) 
Draws a polyline with lines between the points in the point_collection.
Returns self.
Ex:
Assume that {slide 6} is the base-slide of a window.
{slide 6}:draw_polyline([{10 30} {90 20} {65 280} {45 230}])
will draw a polyline with three lines.
c := []
for i from 1 to 100 do
	x := the_program:random_number(0, 350)
	y := the_program:random_number(0, 350)
	p := {point}:new(x, y)
	c:add_last(p)
end for 
{slide 6}:draw_polyline(c)
will draw a polyline with 99 random lines.
Note: This is a drawing operation that will temporarily change the appearance of the gadget. As soon as the gadget is redisplayed the result of this drawing operation will disappear.
#end_method

#begin_method
draw_post_script(string)
Draws the postscript in string.
Returns self.
Ex:
Assume that {slide 6} is the base-slide of a window.
s := "0 1 350 {dup dup 350 div 0 1 setrgbcolor 0 moveto 350 lineto stroke} for"
{slide 6}:draw_post_script(s)
will draw a 350*350 colored area.
There are two special variables cm_width and cm_hight that can be used in the PostScript code. They will evaluate to the width and the height of the gadget.
s := "0 1 cm_width {dup dup cm_width div 0 1 setrgbcolor 0 moveto cm_height lineto stroke} for" 
{slide 6}:draw_post_script(s)
will draw a colored area that covers the whole gadget.
Note: This is a drawing operation that will temporarily change the appearance of the gadget. As soon as the gadget is redisplayed the result of this drawing operation will disappear.
#end_method

#begin_method
draw_rectangle(x, y, width, height) 
Draws a rectangle with the origin at (x, y) and with the size width and height.
Returns self.
Ex:
Assume that {slide 6} is the base-slide of a window.
{slide 6}:draw_rectangle(10, 10, 200, 150)
will draw a rectangle with the origin at (10, 10) and with the width 200 and the height 150.
for s from 5 to 200 by 5 do
	{slide 6}:draw_rectangle(10, 10, s, s)
end for
will draw a number of rectangles with different sizes.
Note: This is a drawing operation that will temporarily change the appearance of the gadget. As soon as the gadget is redisplayed the result of this drawing operation will disappear.
#end_method

#begin_method
draw_string(string, x, y) 
Draws string in the current font at (x, y).
Returns self.
Ex:
Assume that {slide 6} is the base-slide of a window.
{slide 6}:draw_string("Hello", 100, 100)
will draw the string "Hello" at (100, 100).
for s from 0 to 100 do
	x := the_program:random_number(0, 350)
	y := the_program:random_number(0, 350)
	{slide 6}:draw_string(s:as_string, x, y)
end for
will draw the numbers from 0 to 200 at random positions.
Note: This is a drawing operation that will temporarily change the appearance of the gadget. As soon as the gadget is redisplayed the result of this drawing operation will disappear.
#end_method

#begin_method
fill_circle(x1, y1, radius) 
Fills a circle with the center point in (x1, y1) and the radius radius.
Returns self.
Ex:
Assume that {slide 6} is the base-slide of a window.
{slide 6}:fill_circle(100, 100, 50)
will draw a circle.
for x from 0 to 350 by 80 do
	{slide 6}:fill_circle(x, 100, 35)
end for
will draw a number of circles with different x positions.
Note: This is a drawing operation that will temporarily change the appearance of the gadget. As soon as the gadget is redisplayed the result of this drawing operation will disappear.
#end_method

#begin_method
fill_polygon(point_collection) 
Fills a polygon with the points in the point_collection.
Returns self.
Ex:
Assume that {slide 6} is the base-slide of a window.
{slide 6}:fill_polygon([{10 10} {90 20} {65 280} {25 230}])
will fill a polygon with four corners.
c := []
for i from 1 to 20 do
	x := the_program:random_number(0, 350)
	y := the_program:random_number(0, 350)
	p := {point}:new(x, y)
	c:add_last(p)
end for 
{slide 6}:fill_polygon(c)
will fill a polygon with 20 random corners.
Note: This is a drawing operation that will temporarily change the appearance of the gadget. As soon as the gadget is redisplayed the result of this drawing operation will disappear.
#end_method

#begin_method
fill_rectangle(x, y, width, height) 
Fills a rectangle with the origin at (x, y) and with the size width and height.
Returns self.
Ex:
Assume that {slide 6} is the base-slide of a window.
{slide 6}:fill_rectangle(10, 10, 200, 150)
will fill a rectangle with the origin at (10, 10) and with the width 200 and the height 150.
for x from 0 to 300 by 90 do 
	{slide 6}:fill_rectangle(x, 10, 50, 150) 
end for
will fill a number of rectangles with different x positions.
Note: This is a drawing operation that will temporarily change the appearance of the gadget. As soon as the gadget is redisplayed the result of this drawing operation will disappear.
#end_method

#begin_method
frame 
Returns the frame of the gadget in the coordinate system of the slide the gadget is located in.
Returns self.
Ex:
Assume the button my_button is located at (20, 30) and has the width of 60 and the height of 40.
{button my_button}:frame
returns {20 30 60 40}
Note: This method generates garbage. It will be faster to use the x, y, width and height messages instead.
#end_method

#begin_method
height 
Returns the height of the gadget's frame.
Returns self.
Ex:
Assume the button my_button is located at (20, 30) and has the width of 60 and the height of 40.
{button my_button}:height
returns 40
#end_method

#begin_method
paint_rectangle(x, y, width, height, type) 
Pants a rectangle with the origin at (x, y), with the size width and height and with the type type.
The different types are:
#groove_border
#button_border
#gray_bezel_border
#white_bezel_border
Returns self.
Ex:
Assume that {slide 6} is the base-slide of a window.
{slide 6}:paint_rectangle(10, 10, 200, 150, #gray_bezel_border)
will paint a rectangle with the origin at (10, 10), with the width 200 and the height 150 and the type #gray_bezel_border.
for x from 0 to 300 by 90 do 
	{slide 6}:paint_rectangle(x, 10, 50, 150, #button_border) 
end for
will paint a number of rectangles with different sizes.
Note: This is a drawing operation that will temporarily change the appearance of the gadget. As soon as the gadget is redisplayed the result of this drawing operation will disappear.
#end_method

#begin_method
position 
Returns the position of the lower left corner of the gadget in the coordinate system of the slide the gadget is located in.
Ex:
Assume the button my_button is located at (20, 30) and has the width of 60 and the height of 40.
{button my_button}:position
returns {20 30}
Note: This method generates garbage. It will be faster to use the x and y messages instead.
#end_method

#begin_method
reset_draw_state 
Resets the drawing parameters of in the draw-state of the gadget to the default values.
Note: When the gadget is moved or resized the draw-state is also reset. 
However, if the gadget is located in a slide that is moved the draw-state will not be reset
#end_method

#begin_method
resize(width, height) 
Sets the size of the gadget.
Returns self.
Also see shape(left, bottom, width, height) and move(x, y).
#end_method

#begin_method
resize_by(dw, dh) 
Changes the size of the gadget by dw and dh.
Returns self.
Also see shape(left, bottom, width, height) and resize(width, height).
#end_method

#begin_method
set_draw_color(color) 
Sets the draw_color of the draw-state to color.
Returns self.
Ex:
self:set_draw_color({color white})
sets the draw color to the system color white.
c := {color}:new
c:set_rgba(1.0, 0.2, 0.5, 1)
self:set_draw_color(c)
sets the draw color to a pale red color.
#end_method

#begin_method
set_draw_dash(number_collection, offset) 
Sets the draw_dash of the draw-state.
Returns self.
Ex:
self:set_draw_dash([5 5], 0)
#end_method

#begin_method
set_draw_font(font) 
Sets the draw_font of the draw-state to font.
Returns self.
Ex:
self:set_draw_font({font helvetica_bold_24})
sets the draw font to Helvetica Bold 24 points.
#end_method

#begin_method
set_draw_linewidth(width) 
Sets the draw_linewidth of the draw-state to width.
Returns self.
#end_method

#begin_method
set_draw_rotation(angle) 
Sets the draw_rotation of the draw-state to angle.
Returns self.
#end_method

#begin_method
set_draw_scaling(x, y) 
Sets the horizontal draw_scaling of the draw-state to x and the vertical draw_scaling to y.
Returns self.
#end_method

#begin_method
set_draw_translation(dx, dy) 
Sets the horizontal draw_translation of the draw-state to dx and the vertical draw_translation to dy.
Returns self.
#end_method

#begin_method
shape(x, y, width, height) 
Sets the frame of the gadget in the coordinate system of the slide the gadget is located in.
Returns self.
Also see resize(width, height) and move(x, y) (graphic).
#end_method

#begin_method
shape_by(dx, dy, dw, dh) 
Changes the frame of the gadget. 
The x coordinate will be set to the current value + dx.
The y coordinate will be set to the current value + dy.
The width will be set to the current value + dw.
The height coordinate will be set to the current value + dh.
Returns self.
#end_method

#begin_method
size 
Returns the size of the gadget's frame.
Ex:
Assume the button my_button is located at (20, 30) and has the width of 60 and the height of 40.
{button my_button}:size
returns {60 40}
Note: This method generates garbage. It will be faster to use the width and height messages instead.
#end_method

#begin_method
width 
Returns the width of the gadget's frame.
Ex:
Assume the button my_button is located at (20, 30) and has the width of 60 and the height of 40.
{button my_button}:width
returns 60
#end_method

#begin_method
x 
Returns the x coordinate of the gadget's frame.
Ex:
Assume the button my_button is located at (20, 30) and has the width of 60 and the height of 40.
{button my_button}:x
returns 20
#end_method

#begin_method
y 
Returns the y coordinate of the gadget's frame.
Ex:
Assume the button my_button is located at (20, 30) and has the width of 60 and the height of 40.
{button my_button}:y
returns 30
#end_method

Class Methods 

#begin_class_method
new 
You cannot create instances of the class gadget since it is an abstract class.
Ex:
{gadget}:new
raises an exception
Exception:
The message new was sent to the class gadget but gadget is an abstract class which you can't make instances of
#end_class_method